#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent) : QWidget(parent)
{
#if 0
    //窗口是this
    hLayout = new QHBoxLayout(this);//等价于this->setLayout(hLayout);

    btn1 =new QPushButton(QIcon("://1.jpg"),"button1");
    btn2 =new QPushButton("button2");


//    //addWidget 将控件添加到指定布局中
    hLayout->addWidget(btn1);
    hLayout->addWidget(btn2);


    //将当前窗口设置为水平布局
    //this->setLayout(hLayout);
#endif

#if 0//垂直布局

    vLayout = new QVBoxLayout(this);
    for(int i=0;i<4;i++)
    {
        btns[i] = new QPushButton("1");
        vLayout->addWidget(btns[i]);
    }

#endif


#if 0//用数组显示多按钮
    myvector.push_back(new QPushButton("1"));
    myvector.push_back(new QPushButton("2"));
    myvector.push_back(new QPushButton("3"));
    for(auto &value: myvector){
        hLayout->addWidget(value);
    }
#endif

#if 0
    hLayout = new QHBoxLayout;   //this->setLayout(hLayout);
    vLayout = new QVBoxLayout;
    mainLayout = new QHBoxLayout(this);


    mainLayout->addLayout(vLayout);  //左侧的垂直布局
    mainLayout->addLayout(hLayout);  //右侧的水平布局

   //行
    for(int i=0;i<4;i++)
    {
       myvector.push_back(new QPushButton(QString::number(i+1)));
        hLayout->addWidget(myvector.back());
    }

    //列
    for(int i=0;i<5;i++)
    {
        btns[i] = new QPushButton("1");
        vLayout->addWidget(btns[i]);
    }

    //显示5行四列
    for (int row = 0; row < 5; ++row) {
        hLayout = new QHBoxLayout();
        for (int col = 0; col < 4; ++col) {
            QPushButton *button = new QPushButton(QString::number(row * 4 + col + 1));
            hLayout->addWidget(button);
        }
        vLayout->addLayout(hLayout);
    }
#endif


//实现界面关闭
        btn1 = new QPushButton("关闭",this);
        connect(btn1,SIGNAL(clicked(bool)),this,SLOT(close()));

















}
